﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Maticsoft.DBUtility;//Please add references
namespace lcmyjobs.DAL
{
	/// <summary>
	/// 数据访问类:enterprise_reward
	/// </summary>
	public partial class enterprise_reward
	{
		public enterprise_reward()
		{}
        /// <summary>
        /// 批量个更改
        /// </summary>
        /// <param name="keywords">关键字</param>
        /// <param name="value">更改值</param>
        /// <param name="where">更改条件enterprise_rid</param>
        /// <returns></returns>
        public bool UpdateWhere(string keywords, string value, string where)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update enterprise_reward set " + keywords + " = '" + value + "' ");
            strSql.Append(" where enterprise_reward_id in (" + where + ")  ");

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 分页获取悬赏职位信息列表
        /// </summary>
        /// <param name="enterprise_bid">企业ID</param>
        /// <param name="currentPageIndex">当前页</param>
        /// <param name="pageSize">每页显示条目数</param>
        /// <param name="count">总条目数</param>
        /// <returns>返回的DataSet第2个表是企业名称</returns>
        public DataSet GetReward(int enterprise_bid, int currentPageIndex, int pageSize, out int count)
        {
            SqlParameter[] para = 
            {
                new SqlParameter("@enterprise_bid",SqlDbType.Int),
                new SqlParameter("@currentPageIndex",SqlDbType.Int),
                new SqlParameter("@pageSize",SqlDbType.Int),
                new SqlParameter("@count",SqlDbType.Int)
            };

            para[0].Value = enterprise_bid;
            para[1].Value = currentPageIndex;
            para[2].Value = pageSize;
            para[3].Direction = ParameterDirection.Output;

            DataSet ds = DbHelperSQL.RunProcedure("P_Get_enterprise_reward", para, "ds");

            count = Convert.ToInt32(para[3].Value);


            return ds;
        }

		#region  Method

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
		return DbHelperSQL.GetMaxID("enterprise_reward_id", "enterprise_reward"); 
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int enterprise_reward_id)
		{
			int rowsAffected;
			SqlParameter[] parameters = {
					new SqlParameter("@enterprise_reward_id", SqlDbType.Int,4)
};
			parameters[0].Value = enterprise_reward_id;

			int result= DbHelperSQL.RunProcedure("enterprise_reward_Exists",parameters,out rowsAffected);
			if(result==1)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		///  增加一条数据
		/// </summary>
		public int Add(lcmyjobs.Model.enterprise_reward model)
		{
			int rowsAffected;
			SqlParameter[] parameters = {
					new SqlParameter("@enterprise_reward_id", SqlDbType.Int,4),
					new SqlParameter("@enterprise_rid", SqlDbType.Int,4),
					new SqlParameter("@enterprise_bh", SqlDbType.Char,5),
					new SqlParameter("@price", SqlDbType.Float,8),
					new SqlParameter("@releasetime", SqlDbType.DateTime),
					new SqlParameter("@rtime", SqlDbType.SmallInt,2),
					new SqlParameter("@issuccess", SqlDbType.Bit,1),
					new SqlParameter("@status", SqlDbType.TinyInt,1)};
			parameters[0].Direction = ParameterDirection.Output;
			parameters[1].Value = model.enterprise_rid;
			parameters[2].Value = model.enterprise_bh;
			parameters[3].Value = model.price;
			parameters[4].Value = model.releasetime;
			parameters[5].Value = model.rtime;
			parameters[6].Value = model.issuccess;
			parameters[7].Value = model.status;

			DbHelperSQL.RunProcedure("enterprise_reward_ADD",parameters,out rowsAffected);
			return (int)parameters[0].Value;
		}

		/// <summary>
		///  更新一条数据
		/// </summary>
		public bool Update(lcmyjobs.Model.enterprise_reward model)
		{
			int rowsAffected=0;
            SqlParameter[] parameters = {
					new SqlParameter("@enterprise_reward_id", SqlDbType.Int,4),
					new SqlParameter("@enterprise_rid", SqlDbType.Int,4),
					new SqlParameter("@enterprise_bh", SqlDbType.Char,5),
					new SqlParameter("@price", SqlDbType.Float,8),
					new SqlParameter("@releasetime", SqlDbType.DateTime),
					new SqlParameter("@rtime", SqlDbType.SmallInt,2),
					new SqlParameter("@issuccess", SqlDbType.Bit,1),
					new SqlParameter("@status", SqlDbType.TinyInt,1)};
			parameters[0].Value = model.enterprise_reward_id;
			parameters[1].Value = model.enterprise_rid;
			parameters[2].Value = model.enterprise_bh;
			parameters[3].Value = model.price;
			parameters[4].Value = model.releasetime;
			parameters[5].Value = model.rtime;
			parameters[6].Value = model.issuccess;
			parameters[7].Value = model.status;

            DbHelperSQL.RunProcedure("P_Update_enterprise_reward", parameters, out rowsAffected);
			if (rowsAffected > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int enterprise_reward_id)
		{
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from enterprise_reward ");
            strSql.Append(" where enterprise_reward_id=@enterprise_reward_id");

            SqlParameter[] parameters = {
					new SqlParameter("@enterprise_reward_id", SqlDbType.Int,4)
};
            parameters[0].Value = enterprise_reward_id;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string enterprise_reward_idlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from enterprise_reward ");
			strSql.Append(" where enterprise_reward_id in ("+enterprise_reward_idlist + ")  ");
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public lcmyjobs.Model.enterprise_reward GetModel(int enterprise_reward_id)
		{

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select *  from View_enterprise_reward ");
            strSql.Append(" where enterprise_reward_id=@enterprise_reward_id");


			SqlParameter[] parameters = {
					new SqlParameter("@enterprise_reward_id", SqlDbType.Int,4)
};
			parameters[0].Value = enterprise_reward_id;

			lcmyjobs.Model.enterprise_reward model=new lcmyjobs.Model.enterprise_reward();

            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);

			if(ds.Tables[0].Rows.Count>0)
			{
                if (ds.Tables[0].Rows[0]["jobs_name"] != null && ds.Tables[0].Rows[0]["jobs_name"].ToString() != "")
                {
                    model.jobsname = ds.Tables[0].Rows[0]["jobs_name"].ToString();
                }
				if(ds.Tables[0].Rows[0]["enterprise_reward_id"]!=null && ds.Tables[0].Rows[0]["enterprise_reward_id"].ToString()!="")
				{
					model.enterprise_reward_id=int.Parse(ds.Tables[0].Rows[0]["enterprise_reward_id"].ToString());
				}
				if(ds.Tables[0].Rows[0]["enterprise_rid"]!=null && ds.Tables[0].Rows[0]["enterprise_rid"].ToString()!="")
				{
					model.enterprise_rid=int.Parse(ds.Tables[0].Rows[0]["enterprise_rid"].ToString());
				}
				if(ds.Tables[0].Rows[0]["enterprise_bh"]!=null && ds.Tables[0].Rows[0]["enterprise_bh"].ToString()!="")
				{
					model.enterprise_bh=ds.Tables[0].Rows[0]["enterprise_bh"].ToString();
				}
				if(ds.Tables[0].Rows[0]["price"]!=null && ds.Tables[0].Rows[0]["price"].ToString()!="")
				{
					model.price=decimal.Parse(ds.Tables[0].Rows[0]["price"].ToString());
				}
				if(ds.Tables[0].Rows[0]["releasetime"]!=null && ds.Tables[0].Rows[0]["releasetime"].ToString()!="")
				{
					model.releasetime=DateTime.Parse(ds.Tables[0].Rows[0]["releasetime"].ToString());
				}
				if(ds.Tables[0].Rows[0]["rtime"]!=null && ds.Tables[0].Rows[0]["rtime"].ToString()!="")
				{
					model.rtime=int.Parse(ds.Tables[0].Rows[0]["rtime"].ToString());
				}
				if(ds.Tables[0].Rows[0]["issuccess"]!=null && ds.Tables[0].Rows[0]["issuccess"].ToString()!="")
				{
					if((ds.Tables[0].Rows[0]["issuccess"].ToString()=="1")||(ds.Tables[0].Rows[0]["issuccess"].ToString().ToLower()=="true"))
					{
						model.issuccess=true;
					}
					else
					{
						model.issuccess=false;
					}
				}
				if(ds.Tables[0].Rows[0]["status"]!=null && ds.Tables[0].Rows[0]["status"].ToString()!="")
				{
					model.status=int.Parse(ds.Tables[0].Rows[0]["status"].ToString());
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select enterprise_reward_id,enterprise_rid,enterprise_bh,price,releasetime,rtime,issuccess,status ");
			strSql.Append(" FROM enterprise_reward ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
			strSql.Append(" enterprise_reward_id,enterprise_rid,enterprise_bh,price,releasetime,rtime,issuccess,status ");
			strSql.Append(" FROM enterprise_reward ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			SqlParameter[] parameters = {
					new SqlParameter("@tblName", SqlDbType.VarChar, 255),
					new SqlParameter("@fldName", SqlDbType.VarChar, 255),
					new SqlParameter("@PageSize", SqlDbType.Int),
					new SqlParameter("@PageIndex", SqlDbType.Int),
					new SqlParameter("@IsReCount", SqlDbType.Bit),
					new SqlParameter("@OrderType", SqlDbType.Bit),
					new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
					};
			parameters[0].Value = "enterprise_reward";
			parameters[1].Value = "enterprise_reward_id";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  Method
	}
}

